package com.opencfg.core;

import org.apache.commons.pool.ObjectPool;
import org.apache.commons.pool.ObjectPoolFactory;
import org.apache.commons.pool.impl.StackObjectPoolFactory;

public class CommonObjectPool<T> {

	private CommonObjectFactory _commonObjectfactory;
	private ObjectPoolFactory _poolFactory;
	private ObjectPool _pool;

	public CommonObjectPool() {
		_commonObjectfactory = new CommonObjectFactory();
		_poolFactory = new StackObjectPoolFactory(_commonObjectfactory, 10000,
				100);
		_pool = _poolFactory.createPool();
	}

	@SuppressWarnings("unchecked")
	public T getObject() throws Throwable {
		return (T) _pool.borrowObject();
	}

	public void returnObject(T t) throws Throwable {
		_pool.returnObject(t);
	}

}
